<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{$tpshop_config['shop_info_store_title']}</title>
<meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
<meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
<script src="__PUBLIC__/js/jquery-1.8.2.min.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/pc_common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>

</head>

<body>
<include file="Public/header" />

    <div class="breadcrumb-area">
<div class="layout">

           <img src="__STATIC__/images/cart_btn.jpg" >{$Think.lang.mycart}

    </div>
</div>
<link rel="stylesheet" href="__STATIC__/css/cart.css" type="text/css">
<style>
	/*.address tr td { border:#F00 solid 1px; }*/
    /*没选中的 收货地址*/
    .order-address-list table{background-color:inherit; border: 0px solid #CCC;}
    .order-address-list .default{visibility:hidden;}
    /*选中的 收货地址*/
    .address_current{ background-color:#FAFAFA;}
	.address_current .default{visibility:visible;}
</style>
<form name="cart2_form" id="cart2_form" method="post">

    <input name="hd_id" id="hd_id" value="{$hd_id}" type="hidden"/>
    <div class="layout be-table fo-fa ma-bo-45">
    	<div class="con-info">
        	<div class="con-y-info ma-bo-35">
            	<h3 style="margin-top:30px">{$Think.lang.consignee_info} <b>[<a href="javascript:void(0);" onClick="add_edit_address(0);">{$Think.lang.use_new_address} </a>]</b></h3>
                <div id="ajax_address"><!--ajax 返回收货地址--></div>
               <!--  <h3 style="margin-top:30px">自提点</h3>
                <div id="ajax_pickup"></div> -->
            </div>
        	<div class="con-y-info ma-bo-35 con-h" style="display:none;">
            	<h3>{$Think.lang.invoiceinfo} <em>({$Think.lang.shipments_hints} )</em></h3>
                <div class="order-invoice-list">
            		<ul>
            		<li>
                    	<div class="invoice-main fl"><label for="dw">{$Think.lang.Invoice_rise} :</label></div>
                        <div class="invoice-sub fl">
                        	<label class="inv-label">
                        		<input class="officdw" type="text" name="invoice_title" placeholder=" " />
                            </label>
                        </div>
                    </li>
            	</ul>
            	</div>
            </div>
			<div class="con-y-info ma-bo-35 con-h">
            	<h3>{$Think.lang.logisticsinfo} </h3>
                <div class="order-invoice-list">
            		<ul>
                    <foreach name="shippingList" item="v"  key="k">
                        <li>
                            <div class="invoice-main">
                                <input id="{$v.code}" type="radio" name="shipping_code" value="{$v.code}" onClick="ajax_order_price();" <if condition="$k eq 0"> checked="checked" </if> />
                                <label for="gr">{$v.name} <if condition="$v.code eq 'smzt'">({$v.desc})</if></label>
                            </div>
                        </li>
            		</foreach>
	            	</ul>
            	</div>
            </div>
        </div>
		<div class="con-y-info ma-bo-35 con-h">
            	<h3>{$Think.lang.goods_you_buy} </h3>
		</div>
        <div class="sc-area">
        	<div class="dt-order-area">
            	<div class="order-pro-list">
                	<div class="order-pro-list">
                    	<div class="yxspy">
                        	<div class="bv">
                            	<table border="0" cellpadding="0" cellspacing="0">
                                    <thead>
                                        <tr>
                                            <th class="tr-pro" style="text-align:left;">{$Think.lang.goods_name} </th>
                                            <th class="tr-price">{$Think.lang.unit_price_yuan} </th>
                                            <if condition="($user[discount] neq 1)">
                                            	<th class="tr-price" style="display:none;">{$Think.lang.membership_price} </th>
                                            </if>
                                            <th class="tr-quantity">{$Think.lang.buy_num} </th>
                                            <th class="tr-subtotal">{$Think.lang.coping_yuan} </th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>

                        <div class="leiliste">
                        	<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #ECECEC; margin-bottom: 20px;">
                                <tbody>
                                <if condition="$promname">
								 <tr style="border-bottom: 1px solid #ECECEC;">
									<td  colspan="4" style="padding:10px 0 3px;">
									   <b class="cart_tag">{$Think.lang.preferences} </b>
									   <span class="content_tag">({$promname})  <if condition="$total_price.yh_total neq 0">{$Think.lang.active_goods_isfull}{$total_price.selnum}{$Think.lang.jian}（<em>{$Think.lang.has_been_reduced}¥{$total_price.yh_total}</em>)</if></span>
									  <if condition="$total_price.yh_total neq 0"> <div class="right_price" style="margin-right: 35px;">¥ {$total_price.total_header_fee}<br ><em>{$Think.lang.jian1}：¥ {$total_price.yh_total}</em></div></if>
									</td>

								  </tr>
								  </if>

                                <foreach name="cartList" item="v"  key="k">
                                 <if condition="$v[selected] eq '1'">
                                    <tr>
                                        <td class="tr-pro">
                                            <ul class="pro-area-2"  style="padding-left:0;">
                                                <li>
                                                  <a title="{$bi,$v[goods_id]|goods_name_shift}" target="_blank" href="{:U('Home/Goods/goodsInfo',array('id'=>$v[goods_id]))}" seed="item-name">{$bi,$v[goods_id]|goods_name_shift}</a>
                                                </li>
                                             </ul>
                                         </td>
                                        <!-- 预付订金商品的价格为空 -->
                                        <td class="tr-price te-al">¥{$v.goods_price}</td>
                                        <if condition="($user[discount] neq 1)">
                                        	<td class="tr-price te-al"  style="display:none;">¥{$v.member_goods_price}</td>
                                        </if>
                                        <td class="tr-quantity te-al">{$v.goods_num}</td>
                                        <td rowspan="1" class="tr-subtotal te-al">
                                        <p><b>￥{$v.goods_fee}</b></p>
                                        </td>
                                    </tr>
                                    </if>
                                </foreach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="order-pro-total">
                	<div class="fl wctmes" style="padding-left: 0;">

						<if condition="$userstate" >
                        <div class="syyouhui pa-to-15">
                        	<div class="duoxuk">
                            	 <label class="fo-fa-ta" for="order-chick">{$Think.lang.coupons} :</label>&nbsp;&nbsp;{$Think.lang.coupon_hints}
                       		</div>
                            <div class="byicd" style="padding-left: 0;">
                            	<div class="zhiwfnka">
                                    	<table border="0" cellpadding="0" cellspacing="0">
                                            <tbody>
                                                <tr>
                                                    <td>
                                                    <input type="radio" class="radio vam ma-ri-10" name="couponTypeSelect" checked value="1"  onClick="ajax_order_price();" />
                                                     <select id="coupon_id" name="coupon_id" class="vam ou-no" onChange="ajax_order_price();">
                                                         <option value="0">{$Think.lang.chooses_coupons} </option>

					                                      <foreach name="couponList" item="v"  key="k">
                                                         	<option value="{$v['id']}">{$v['name']}</option>

          		                                                </foreach>


                                                     </select>
                                                    &nbsp;&nbsp;&nbsp;
                                                    <!--  <input type="radio" class="radio vam ma-ri-10" name="couponTypeSelect" value="2"  onClick="ajax_order_price();" />
                                                   <input type="text" name="couponCode" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入优惠券代码" />
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" /> -->
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                    <label class="fo-fa-ta" for="order-chick">{$Think.lang.integral_payment} :</label>
                                                    <input type="text" id="pay_points" name="pay_points" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="{$Think.lang.please_enter_integral}"    onpaste="this.value=this.value.replace(/[^\d]/g,'')" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')"/>
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="{$Think.lang.uses} " onClick="ajax_order_price();" />
                                                    <?php echo tpCache('shopping.point_rate');?> {$Think.lang.integral_worth_1yuan}  &nbsp;&nbsp;  {$Think.lang.available_integral} {$user['pay_points']}{$Think.lang.fen}
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                    <label class="fo-fa-ta" for="order-chick">{$Think.lang.balance_payment} :</label>
                                                    <input type="text" id="user_money" name="user_money" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="{$Think.lang.please_enter_balance} "   onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="{$Think.lang.uses} " onClick="ajax_order_price();" />
                                                        {$Think.lang.available_balance}¥ {$user['user_money']}
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                </div>
                            </div>
                        </div>
						</if>
                    </div>
                    <div class="fr wcnhy">
                    	<div class="fzoubddv">
                        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td class="tal">{$Think.lang.goodstotal}  ：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                           <em id="order-cost-area">  {$total_price.total_header_fee} </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">{$Think.lang.freight} ：</td>
                                        <td class="tar">&nbsp;¥&nbsp;
                                               <em id="postFee">0.00</em>
                                        </td>
                                    </tr>
									<if condition="$userstate" >
                                    <tr>
                                        <td class="tal">{$Think.lang.coupons} ：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="couponFee">0.00</span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">{$Think.lang.uses_integral} ：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="pointsFee">{$total_price.total_header_fee} </span> </em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tal">{$Think.lang.use_balance} :</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="balance">0.00</span> </em>
                                        </td>
                                    </tr>
									</if>
                                    <tr>
                                        <td class="tal">{$Think.lang.preferentialactivities} ：</td>
                                        <td class="tar">-&nbsp;¥&nbsp;
                                          <em><span id="order_prom_amount"> {$total_price.yh_total}</span> </em>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <p class="yifje-order">
                            	<span class="p-subtotal-price">{$Think.lang.dealwith_1}  ：
                                    <b class="total">¥</b>
                                    <b class="total" id="payables">{$total_price.total_fee}</b>
                                </span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="order-action-area te-al-ri">
            	<div class="woypdbe sc-acti-list pa-to-20">
                	<!--<span class="p-subtotal-price">应付总额：<b>¥<span class="vab" id="payableTotal">2276.00</span></b></span>-->
                    <a class="Sub-orders gwc-qjs" href="javascript:void(0);" onClick="submit_order();"><span>{$Think.lang.submitsorder} </span></a>
                </div>
            </div>
        </div>
    </div>
</form>
<!--------footer-开始-------------->
<include file="Public/footer" />
<!--------footer-结束-------------->
<script>
$(document).ready(function(){
	ajax_address(); // 获取用户收货地址列表
	//ajax_order_price();
});
/**
* 新增修改收货地址
* id 为零 则为新增, 否则是修改
*  使用 公共的 layer 弹窗插件  参考官方手册 http://layer.layui.com/
*/
<if condition="!$userstate" >
function add_edit_address(id)
{
	if(id > 0)
		var url = "/index.php?m=Home&c=Address&a=edit_address&scene=1&call_back=call_back_fun&id="+id; // 修改地址
	else
		var url = "/index.php?m=Home&c=Address&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
	layer.open({
		type: 2,
		title: '{$Think.lang.addaddress_1} ',
		shadeClose: true,
		shade: 0.8,
		area: ['880px', '580px'],
		content: url,
	});
}
<else />
function add_edit_address(id)
{
	if(id > 0)
		var url = "/index.php?m=Home&c=User&a=edit_address&scene=1&call_back=call_back_fun&id="+id; // 修改地址
	else
		var url = "/index.php?m=Home&c=User&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
	layer.open({
		type: 2,
		title: '{$Think.lang.addaddress_1} ',
		shadeClose: true,
		shade: 0.8,
		area: ['880px', '580px'],
		content: url,
	});
}
</if>
// 添加修改收货地址回调函数
function call_back_fun(v){
	layer.closeAll(); // 关闭窗口
	ajax_address(); // 刷新收货地址
}

// 删除收货地址
<if condition="!$userstate" >
function del_address(id)
{
    if(!confirm("{$Think.lang.sure_delete} "))
	  return false;
	  $.ajax({
			url:"/index.php?m=Home&c=Address&a=del_address&id="+id,
  			 success: function(data){
				ajax_address(); // 刷新收货地址
                $('#ajax_pickup .order-address-list').removeClass('address_current');
             }
		  });
}
<else />
function del_address(id)
{


	   $.artConfim('{$Think.lang.sure_delete} ', 'confimFrame', 'zh_cn', function (cancel) {
			if (cancel) {
				return false;
			}
		})
	  $.ajax({
			url:"/index.php?m=Home&c=User&a=del_address&id="+id,
  			 success: function(data){
				ajax_address(); // 刷新收货地址
                $('#ajax_pickup .order-address-list').removeClass('address_current');
             }
		  });
}
</if>
/*
* ajax 获取当前用户的收货地址列表
*/
function ajax_address(){
	$.ajax({
		url:"{:U('Home/Cart/ajaxAddress')}",//+tab,
		success: function(data){
			$("#ajax_address").html('');
			$("#ajax_address").append(data);

		}
	});
	ajax_order_price();

}



// 切换收货地址
function swidth_address(obj)
{
    var province_id = $(obj).attr('data-province-id');
    var city_id = $(obj).attr('data-city-id');
    var district_id = $(obj).attr('data-district-id');
    if (typeof($(obj).attr('data-province-id')) != 'undefined') {
        ajax_pickup(province_id,city_id,district_id,0);
    }
    $(".order-address-list").removeClass('address_current');
    $(obj).parent().parent().parent().parent().parent().addClass('address_current');
    if($('#address_id').length > 0)
        ajax_order_price(); // 计算订单价格
}

/**
 * 获取用户自提点和推荐自提点
 * @param type 1：用户自提点 ，0：用户自提点和推荐自提点
 * @param province_id 省
 * @param city_id 市
 * @param district_id 区
 */
function ajax_pickup(province_id, city_id, district_id,show) {
    $.ajax({
        type: 'GET',
        url: "{:U('Home/Cart/ajaxPickup')}",//+tab,
        data: {province_id: province_id, city_id: city_id, district_id: district_id,show:show},
        success: function (data) {
            $("#ajax_pickup").html('');
            $("#ajax_pickup").append(data);
        }
    });
}
//更换自提点
function replace_pickup(province_id, city_id, district_id) {
    var url = "/index.php?m=Home&c=Cart&a=replace_pickup&call_back=call_back_pickup&province_id="+province_id+"&city_id="+city_id+"&district_id="+district_id;
    layer.open({
        type: 2,
        title: '{$Think.lang.addaddress_1} ',
        shadeClose: true,
        shade: 0.8,
        area: ['880px', '580px'],
        content: url,
    });
}
// 添加自提点地址回调函数
function call_back_pickup(province_id,city_id,district_id){
    layer.closeAll(); // 关闭窗口
    ajax_pickup(province_id, city_id, district_id,1);
}


// 获取订单价格
function ajax_order_price()
{
//	alert($('#cart2_form').serialize());
	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=order_price&nosubmit=1",// 你的formid
        dataType: "json",
		success: function(data){

			if(data.status != 1)
			{
				// alert(data.msg); //执行有误

				layer.alert(data.msg, {icon: 2});


				// 登录超时
				if(data.status == -100)
					location.href ="{:U('Home/User/login')}";

				return false;
			}
			// console.log(data);
			//$("#couponFee, #pointsFee, #order_prom_amount").css('display','none');
			$("#order-cost-area").text(data.result.goodsFee);
			$("#postFee").text(data.result.postFee); // 物流费
			$("#couponFee").text(data.result.couponFee);// 优惠券
			$("#balance").text(data.result.balance);// 余额
			$("#pointsFee").text(data.result.pointsFee);// 积分支付
			$("#payables").text(data.result.payables);// 应付
			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动
		}
	});
}

// 提交订单
ajax_return_status = 1;
function submit_order()
{
	if(ajax_return_status == 0)
	    return false;

	ajax_return_status = 0;

	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
        dataType: "json",
		success: function(data){


			if(data.status != '1')
			{
				// alert(data.msg); //执行有误

				if(data.status=="-3")
				{
						add_edit_address(0);
				}
				else
				{
						layer.alert(data.msg, {icon: 2});
				}
				// 登录超时
				if(data.status == -100)
					location.href ="{:U('Home/User/login')}";

				ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请求

				return false;
			}
			//alert();
			// console.log(data);
//			$("#postFee").text(data.result.postFee); // 物流费
//			$("#couponFee").text(data.result.couponFee);// 优惠券
//			$("#balance").text(data.result.balance);// 余额
//			$("#pointsFee").text(data.result.pointsFee);// 积分支付
//			$("#payables").text(data.result.payables);// 应付
//			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动

			layer.msg('{$Think.lang.order_success_hints}', {
			  icon: 1,   // 成功图标
			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
			}, function(){ // 关闭后执行的函数
					location.href = "/index.php?m=Home&c=Cart&a=cart4&order_id="+data.result; // 跳转到结算页
			});
		}
	});
}
</script>
</body>
</html>
